#pragma once
#include <string>
#include <vector>
using namespace std;

#define NO_EXCHANGE_VALUE
#include "TPack.h"

class gmd_node
{
public:
	gmd_node()
	{
		children = NULL;
	}
	~gmd_node()
	{
		delete_children(children);
	}

	static gmd_node* new_children(int count)
	{
		return new gmd_node[count];
	}

	static void delete_children(gmd_node* children)
	{
		if ( children != NULL )
			delete[] children;
	}
	static wchar_t* prefix_flag;
public:
	unsigned int version;
	unsigned short count;

	unsigned char type;
	wstring name;
	vector<unsigned char> values;	
	wstring strval;
	wstring prefix;

	gmd_node* children;
};

class gmd_manager
{
	
public:
	gmd_manager(void);
	~gmd_manager(void);

	void decode_buffer(unsigned char* buf, int len, unsigned char mask);
	void decode_string(wstring& wstr);

	bool parse_gmd_file(const char* filename);
	int parse_gmd_filebuffer(const char* buffer, size_t size);
	size_t parse_gmd_file(const char* buffer, size_t size, gmd_node* node);

	void trace_gmd_nodes(gmd_node* node);

};

